<template>
  <div>
    <el-cascader
      clearable
      :options="options"
      :props="prop"
      :value="currentValue"
      :placeholder="placeholder"
      style="width: 100%;"
      @change="setCurrentValue"
    />
  </div>
</template>
<script>
export default {
  name: 'SystemType',
  props: {
    /** 传入的配置相关信息  具体见element文档 */
    prop: {
      type: Object,
      default: () => {
        return {};
      }
    },
    /** 传入的值 */
    value: {
      type: String,
      default: null
    },
    showDesc: {
      type: Boolean,
      default: true
    },
    placeholder: {
      type: String,
      default: '请选择'
    },
    /**
     * 传入的符合[value:'',label:'',children:[{value:'',label:'',children:[]}]]格式的数据
     * value 和label的值可通过prop进行配置
     */
    options: {
      type: Array,
      default: () => {
        return [];
      }
    }
  },
  data() {
    return {
      currentValue: [this.value]
    };
  },
  watch: {
    currentValue: {
      handler(newV) {
        console.log(newV, 'currentValue');
      }
    },
    value: {
      handler(newV) {
        if (newV === null) {
          this.currentValue = newV;
        }
      }
    }
  },
  mounted: function() {},
  methods: {
    setCurrentValue(val) {
      this.currentValue = val;
      this.$emit('input', val[val.length - 1]);
    }
  }
};
</script>
